package com.javarush.test.level26.lesson15.big01.command;

import com.javarush.test.level26.lesson15.big01.ConsoleHelper;
import com.javarush.test.level26.lesson15.big01.CurrencyManipulator;
import com.javarush.test.level26.lesson15.big01.CurrencyManipulatorFactory;
import com.javarush.test.level26.lesson15.big01.exception.InterruptOperationException;

/**
 * Created by admin on 18.04.2015.
 */
class WithdrawCommand implements Command{
    @Override
    public void execute() throws InterruptOperationException {
        CurrencyManipulator manipulator=CurrencyManipulatorFactory.getManipulatorByCurrencyCode(ConsoleHelper.askCurrencyCode());
        while (true){
            ConsoleHelper.writeMessage("Enter sum");
            String s=ConsoleHelper.readString();
            int sum=0;
            try{
                sum=Integer.parseInt(s);
            }catch (NumberFormatException e){
                System.out.print("Incorrect");
                continue;
            }
            if(manipulator.isAmountAvailable(sum)) break;
            else System.out.print("Incorrect");
        }
    }
}
